﻿@using Kobets.Automation.Chimera.Common

@using (var acc = Html.JQueryUI().Begin(new Accordion(new { id = "accordion" }).OnChange("AccOnChange").Collapsible(true)))
{
    var groups = ((Agent[])(ViewBag.Agents)).Where(a => !String.IsNullOrWhiteSpace(a.Group)).Select(a => a.Group).Distinct().ToList();

    if (groups.Count > 0)
    {
        foreach (var group in groups)
        {
            using (acc.BeginPanel(group))
            {
                foreach (var text in ((Agent[])(ViewBag.Agents)).Where(a => !String.IsNullOrWhiteSpace(a.Group) && a.Group == @group).OrderBy(o => o.Name).Select(a => a.Name + " - " + a.Status))
                {
                    <p>@text</p>
                }
            }
        }
    }

    var unbinded = ((Agent[]) (ViewBag.Agents)).Where(a => String.IsNullOrWhiteSpace(a.Group)).OrderBy(o => o.Name).ToList();

    if (unbinded.Count > 0)
    {
        using (acc.BeginPanel("Unbinded"))
        {
            foreach (var text in unbinded.Select(a => a.Name + " - " + a.Status))
            {
                <p>@text</p>
            }
        }
    }
}

<div class="sidebar-link">@Ajax.ActionLink("Refresh", "Refresh", new AjaxOptions { UpdateTargetId = "sidebar", HttpMethod = "GET", OnSuccess = "$( '#accordion' ).accordion();" })</div>
